# Maintainer: Mazhar Hussain <realmazharhussain@gmail.com>

_realname=gst-plugins-rs
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=1.26.1
_tag=gstreamer-${pkgver}
pkgrel=3
pkgdesc='GStreamer plugins written in Rust (mingw-w64)'
arch=(any)
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs'
license=('spdx:LGPL-3.0-or-later AND Apache-2.0 AND MIT AND MPL-2.0')
depends=(${MINGW_PACKAGE_PREFIX}-gtk4
         ${MINGW_PACKAGE_PREFIX}-libsodium
         ${MINGW_PACKAGE_PREFIX}-gstreamer
         ${MINGW_PACKAGE_PREFIX}-gst-plugins-base
         ${MINGW_PACKAGE_PREFIX}-gst-plugins-bad-libs
         ${MINGW_PACKAGE_PREFIX}-libwebp
         ${MINGW_PACKAGE_PREFIX}-dav1d)
makedepends=(${MINGW_PACKAGE_PREFIX}-rust
             ${MINGW_PACKAGE_PREFIX}-cargo-c
             ${MINGW_PACKAGE_PREFIX}-cmake
             ${MINGW_PACKAGE_PREFIX}-pkgconf
             ${MINGW_PACKAGE_PREFIX}-nasm
             ${MINGW_PACKAGE_PREFIX}-rust-bindgen
             git)
source=("${url}/-/archive/${_tag}/${_realname}-gstreamer-${_tag}.tar.bz2")
sha256sums=('5f265553f6b94b561e42fef747ff61d9e0b26809a2a7a03031118be65407af1a')

prepare() {
  mv "${_realname}-${_tag}-"* "${_realname}-${_tag}" && cd "${_realname}-${_tag}"

  cargo update -p aws-lc-rs --precise 1.13.1
  cargo fetch --locked
}

_cargo_opts=(--workspace
             --offline
             --release
             --meson-paths
             --library-type=cdylib
             --prefix="${MINGW_PREFIX}"
             --exclude gst-plugin-csound
             --exclude gst-plugin-vvdec
             --features gtk_v4_16)

if [[ ${CARCH} == aarch64 ]]; then
  _cargo_opts+=(--exclude gst-plugin-ndi
                --exclude gst-plugin-sodium)
fi

build() {
  cd "${_realname}-${_tag}"

  MSYS2_ARG_CONV_EXCL="--prefix=" cargo cbuild "${_cargo_opts[@]}"
}

check() {
  cd "${_realname}-${_tag}"

  MSYS2_ARG_CONV_EXCL="--prefix=" cargo ctest "${_cargo_opts[@]}" --target-dir=tests-build
}

package() {
  cd "${_realname}-${_tag}"

  MSYS2_ARG_CONV_EXCL="--prefix=" cargo cinstall "${_cargo_opts[@]}" --destdir="${pkgdir}"

  install -Dm644 -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/" LICENSE*
}
